<template>
  <div class="index-image">
    <el-image class="header-bg"
              style="width: 100%; height: 100%"
              :src="urlBodyTop"
              :fit="fit"></el-image>
    <div class="header-wrapper">
      <div class="head-image pull-left">
        <el-image class="avatar head-image-avatar"
                  :src="image"
                  :fit="fit"></el-image>
      </div>
      <div class="user-info pull-left">
        <div class="name" style="margin-top: 36px;margin-bottom: 16px;">
          <span class="pull-left-name" v-if="type === 'student'">{{ name + $t('bodyHeaders.stu') }}</span>
          <span class="pull-left-name" v-else-if="type === 'teacher'">{{ name + $t('bodyHeaders.tea') }}</span>
          <span class="pull-left-name" v-else-if="type === 'admin'">{{ name + $t('bodyHeaders.admin') }}</span>
        </div>
      </div>
    </div>
  </div>
</template>



<script>
import "@/styles/css/el.css"
import {imageGet} from "@/apis/common";

export default {
  props:  {
  },
  name: "IndexImage",
  data() {
    return {
      name: '',
      image: require("../../assets/common/null_avatar_image.jpg"),
      info: '',
      type: '',
      // 图片伸展方式
      fit: 'cover',
      // 静态页面资源
      urlBodyTop: 'https://courseweb.ulearning.cn/common/img/hnylbk/courseList_banner.png',
    }
  },
  created() {

    // this.image = `/api/common/download?name=b74655e9-cbba-4f93-a40a-145b41e40f85.jpg`

    // 获取学生、教师姓名
    this.type = localStorage.getItem("type")
    this.init()
    },
  methods: {
    async init(){
      // 获取用户信息
      let id = localStorage.getItem("id")
      let type = localStorage.getItem("type")
      this.name = localStorage.getItem("name")
      // 获取用户头像地址
      imageGet(id).then((resp) => {
        if (resp?.data?.code == 1 && resp?.data?.data != null) {
          // 请求用户头像
          this.image = `/api/common/download?name=${resp?.data?.data}`
        }
      })
    },


  },

}
</script>

<style scoped>


body > .el-container {
  margin-bottom: 40px;
}


*, :after, :before {
  box-sizing: border-box;
}

body html {
  font-size: 14px;
}

a {
  text-decoration: none;
}


.index-page .content-container {
  width: 1170px;
}

.content-container {
  margin: auto;
}

.header-wrapper {
  margin: auto;
}

.login-wrapper {
  float: left !important;
  display: block;
  width: 290px;
  text-align: left;
}

.login-wrapper-image {
  display: inline-block;
  height: 40px;
  vertical-align: middle;
  overflow: clip;
}

.pull-right {
  float: right !important;
}

.btn-login {
  display: inline-block;
  vertical-align: middle;
}

.ulearning-tools {
  display: inline-block;
}

.ulearning-tools .tool-item {
  color: #444444;
  padding: 2px 12px;
  cursor: pointer;
}

.iconfont {
  margin-right: 6px;
  vertical-align: middle;
}

.index-header {
  position: fixed;
  top: 0;
  z-index: 11;
  width: 100%;
  line-height: 60px;
}

.index-page .index-header .btn-login {
  display: inline-block;
  vertical-align: middle;
}

.index-page .index-body {
  padding-top: 60px;
}

.index-image {
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 50%;
  position: relative;
  height: 120px;
}

.header-bg {
  position: absolute;

  transform: translateX(-50%);
  height: 100%;

}


.user-control .user-info {
  display: inline-block;
}

.user-menu-component {
  vertical-align: middle;
  display: inline-block;
  text-align: center;
  line-height: 1;
}

.user-menu-component .user-control {
  position: relative;
}

.user-menu-component .avatar {
  border-radius: 100%;
  width: 32px;
  height: 32px;
}

.avatar {
  vertical-align: middle;
}

.user-menu-component .user-info .name {
  display: inline-block;

}

.btn-i18n {
  margin-left: 8px;
  display: inline-block;
  vertical-align: middle;
}

.tool-item:hover {
  color: #ea5947;
}

.header-wrapper {
  position: relative;
  max-width: 1170px;
}

.head-image {
  margin: 20px 30px;
  padding: 3px;
  border-radius: 100%;
  border: 2px solid #fff;
  background-color: transparent;
  width: 80px;
  height: 80px;
  overflow: hidden;
}
.i18n-component .locale-control{
  position: relative;
  background-color: #cbcbd1;
  text-align: center;
  border-radius: 100%;
  width: 30px;
  height: 30px;
  line-height: 30px;
  color: #fff;
}
.i18n-component{
  line-height: 1;
  text-align: center;
}

.pull-left {
  float: left !important;
}

.head-image-avatar {
  width: 70px;
  height: 70px;
  border-radius: 100%;
}


.course-list-body {
  position: relative;
}

.index-footer {
  position: relative;
}

.pull-left-name {
  color: #fff;
  max-height: 36px;
  line-height: 18px;
  font-size: 18px;
  overflow: hidden;
}

</style>